package cn.eeepay.boss.action.workOrder;

import cn.eeepay.boss.system.DataSource;
import cn.eeepay.boss.system.SystemLog;
import cn.eeepay.framework.db.pagination.Page;
import cn.eeepay.framework.model.workOrder.WorkCensusFilter;
import cn.eeepay.framework.service.workOrder.WorkCensusService;
import cn.eeepay.framework.util.Constants;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 工单统计
 */
@RequestMapping("/workCensus")
@Controller
public class WorkCensusAction {

    private Logger log = LoggerFactory.getLogger(WorkWarningAction.class);

    @Resource
    private WorkCensusService workCensusService;

    /**
     * 投诉总量统计-组织获取
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/getCountTeamList")
    @ResponseBody
    public Map<String,Object> countTeamWork(){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{

            workCensusService.getCountTeamList(msg);
        } catch (Exception e){
            log.error("投诉总量统计-组织获取异常!",e);
            msg.put("status", false);
            msg.put("msg", "投诉总量统计-组织获取异常!");
        }
        return msg;
    }


    /**
     * 投诉总量统计
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/countTeamWork")
    @ResponseBody
    public Map<String, Object> countTeamWork(@RequestParam("info") String param, @ModelAttribute("page") Page<WorkCensusFilter> page) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.countTeamWork(info, page, msg);
        } catch (Exception e) {
            log.error("投诉总量统计异常!", e);
            msg.put("status", false);
            msg.put("msg", "投诉总量统计异常!");
        }
        return msg;
    }

    /**
     * 投诉总量统计-汇总
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/countTeamWorkCount")
    @ResponseBody
    public Map<String, Object> countTeamWorkCount(@RequestParam("info") String param) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.countTeamWorkCount(info, msg);
        } catch (Exception e) {
            log.error("投诉总量统计-汇总!", e);
            msg.put("status", false);
            msg.put("msg", "投诉总量统计-汇总!");
        }
        return msg;
    }

    /**
     * 导出投诉总量统计
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/exportTeamWork")
    @ResponseBody
    @SystemLog(description = "投诉总量统计导出",operCode = "workCensus.exportTeamWork")
    public Map<String, Object> exportTeamWork(@RequestParam("info") String param, HttpServletResponse response, HttpServletRequest request) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.exportTeamWork(info, response, msg);
        } catch (Exception e) {
            log.error("导出投诉总量统计异常!", e);
            msg.put("status", false);
            msg.put("msg", "导出投诉总量统计异常!");
        }
        return msg;
    }

    /**
     * 所属代理商被投诉排名
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/countAgentWork")
    @ResponseBody
    public Map<String, Object> countAgentWork(@RequestParam("info") String param, @ModelAttribute("page") Page<WorkCensusFilter> page) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.countAgentWork(info, page, msg);
        } catch (Exception e) {
            log.error("下级代理商被投诉排名异常!", e);
            msg.put("status", false);
            msg.put("msg", "下级代理商被投诉排名异常!");
        }
        return msg;
    }
    /**
     * 一级代理商被投诉排名
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/countAgentWork2")
    @ResponseBody
    public Map<String, Object> countAgentWork2(@RequestParam("info") String param, @ModelAttribute("page") Page<WorkCensusFilter> page) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.countAgentWork2(info, page, msg);
        } catch (Exception e) {
            log.error("下级代理商被投诉排名异常!", e);
            msg.put("status", false);
            msg.put("msg", "下级代理商被投诉排名异常!");
        }
        return msg;
    }

    /**
     * 下级代理商被投诉排名-汇总
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/countAgentWorkCount")
    @ResponseBody
    public Map<String, Object> countAgentWorkCount(@RequestParam("info") String param, @ModelAttribute("page") Page<WorkCensusFilter> page) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.countAgentWorkCount(info, msg);
        } catch (Exception e) {
            log.error("下级代理商被投诉排名-汇总异常!", e);
            msg.put("status", false);
            msg.put("msg", "下级代理商被投诉排名-汇总异常!");
        }
        return msg;
    }

    /**
     * 一级代理商被投诉排名-汇总
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/countAgentWorkCount2")
    @ResponseBody
    public Map<String, Object> countAgentWorkCount2(@RequestParam("info") String param, @ModelAttribute("page") Page<WorkCensusFilter> page) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.countAgentWorkCount2(info, msg);
        } catch (Exception e) {
            log.error("下级代理商被投诉排名-汇总异常!", e);
            msg.put("status", false);
            msg.put("msg", "下级代理商被投诉排名-汇总异常!");
        }
        return msg;
    }

    /**
     * 导出下级代理商被投诉排名
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/exportAgentWork")
    @ResponseBody
    @SystemLog(description = "下级代理商被投诉排名导出",operCode = "workCensus.exportAgentWork")
    public Map<String, Object> exportAgentWork(@RequestParam("info") String param, HttpServletResponse response, HttpServletRequest request) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.exportAgentWork(info, response, msg);
        } catch (Exception e) {
            log.error("导出下级代理商被投诉排名异常!", e);
            msg.put("status", false);
            msg.put("msg", "导出下级代理商被投诉排名异常!");
        }
        return msg;
    }

    /**
     * 一级代理商被投诉排名
     */
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    @RequestMapping(value = "/exportAgentWork2")
    @ResponseBody
    @SystemLog(description = "一级代理商被投诉排名导出",operCode = "workCensus.exportAgentWork2")
    public Map<String, Object> exportAgentWork2(@RequestParam("info") String param, HttpServletResponse response, HttpServletRequest request) {
        Map<String, Object> msg = new HashMap<String, Object>();
        try {
            WorkCensusFilter info = JSONObject.parseObject(param, WorkCensusFilter.class);
            workCensusService.exportAgentWork2(info, response, msg);
        } catch (Exception e) {
            log.error("导出下级代理商被投诉排名异常!", e);
            msg.put("status", false);
            msg.put("msg", "导出下级代理商被投诉排名异常!");
        }
        return msg;
    }

}
